package com.zf.shopping.controller;

import com.zf.shopping.bean.Result;
import com.zf.shopping.model.Category;
import com.zf.shopping.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 添加或编辑类别
     * @param category
     * @return
     */
    @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST)
    @ResponseBody
    public Result addOrUpdate(@RequestBody Category category) {

        return categoryService.addOrUpdate(category);
    }

    /**
     * 通过id删除类别
     * @param categoryId
     * @return
     */
    @RequestMapping(value = "/deleteById", method = RequestMethod.GET)
    @ResponseBody
    public Result deleteById(@RequestParam("categoryId") Integer categoryId) {

        return categoryService.deleteById(categoryId);
    }

    /**
     * 获取单个类别
     * @param categoryId
     * @return
     */
    @RequestMapping(value = "/getOne", method = RequestMethod.GET)
    @ResponseBody
    public Category getOne(@RequestParam("categoryId") Integer categoryId) {

        return getOne(categoryId);
    }


    /**
     * 获取所有的
     * @return
     */
    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    @ResponseBody
    public List<Category> getAll() {

        return categoryService.getAll();
    }
}
